<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 1. 导入 vue 文件 -->
    <script src="./lib/vue_2.5.22.js"></script>
    <script src="./lib/vue-router_3.0.2.js"></script>
</head>

<body>
    <div id="app">
        <!-- 2. 添加路由链接 -->
        <router-link to="/user">User</router-link>
        <router-link to="/register">Register</router-link>
        <!-- 3. 添加路由填充位 -->
        <router-view></router-view>
    </div>
    <script>
        // 4. 定义路由组件
        var User = {
            template: '<h1>User 组件</h1>'
        };
        var Register = {
            template: '<h1>Register 组件</h1>'
        };
        // 5. 配置路由规则并创建路由实例
        const router = new VueRouter({
            // 所有的路由规则
            routes: [{
                path: '/',
                redirect: '/user' //路由重定向
            }, {
                path: '/user',
                component: User
            }, {
                path: '/register',
                component: Register
            }]
        })
        var vm = new Vue({
            el: '#app',
            data: {

            },
            //6. 把路由挂载到 Vue 根实例中
            // router: router
            router
        });
    </script>
</body>

</html>